<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2017/12/21
 * Time: 9:47
 */

namespace app\admin\controller;
use think\Db;
use app\admin\validate\LifeValidate;

class LifeController extends CommonController
{
    /**
     * 获取生活管理列表数据
     */
    public function getLifeTask()
    {
        $rows = $_POST['rows'];
        $page = $_POST['page'];
        if ($_POST['keyword'] != '') {
            $where['a.life_name|u.user_username|u.user_phone'] = $_POST['keyword'];
        }
        if ($_POST['category'] != '') {
            $where['udr.region_name'] = $_POST['category'];
        }
        if ($_POST['life_template'] != '') {
            $where['a.life_template'] = $_POST['life_template'];
        }
        if ($_POST['status'] != '') {
            $where['a.life_status'] = $_POST['status'];
        }
        if ($_POST['province'] != '') {
            $where['a.province'] = $_POST['province'];
        }
        if ($_POST['city'] != '') {
            $where['a.city'] = $_POST['city'];
        }
        if ($_POST['area'] != '') {
            $where['a.area'] = $_POST['area'];
        }
        $sh = '1';
        $where['team_id'] = session('loginSession')['team_id'];//团队ID;
        $res = Db::table('up_life')->alias('a')
            ->where($where)
            ->join('up_u_user u', 'u.user_id=a.examine_user_id', 'left')
            ->join('up_dic_region udr', 'udr.region_id = a.category_region_id')
            ->field('a.*,u.user_username,u.user_phone,udr.region_name')
            ->limit($rows * ($page - 1), $rows)
            ->order('a.life_status desc')
            ->select();
        $total = Db::table('up_life')->alias('a')
            ->where($where)
            ->join('up_u_user u', 'u.user_id=a.examine_user_id', 'left')
            ->count();
        foreach ($res as $key => &$vo) {
            $uid = session('loginSession')['user_id'];
            $whereMap['user_id'] = $uid;
            $user_id = Db::table('up_team')->where($whereMap)->field('user_id')->find();
            if ($user_id['user_id'] != '') {
                //如果是团队创建人直接有所有权限
                $vo['is_examine'] = 1;
                $vo['is_delete'] = 1;
                $vo['is_update'] = 1;//修改按钮
            } else {
                $whereUp['team_id'] = session('loginSession')['team_id'];//团队ID
                $whereUp['team_member_user_id'] = $uid;
                //查询这个人在这个团队权限
                $team_member_role = Db::table('up_team_members')->where($whereUp)->field('team_member_role')->find();
                $whereRole['team_role'] = $team_member_role['team_member_role'];
                $whereRole['team_id'] = 1;
                //查询这个在在这个群里面的权限
                $RoleArray = Db::table('up_team_role')->where($whereRole)->field('team_role_detail')->find();
                if (strpos($RoleArray['team_role_detail'], $sh) !== false) {
                    //赋予审核权限
                    $vo['is_examine'] = 1;
                    $vo['is_update'] = 1;//修改按钮
                } else {
                    //没有审核权限
                    $vo['is_examine'] = 0;
                }
                if ($vo['publisher_uid_id'] == $uid) {
                    $vo['is_delete'] = 1;
                    $vo['is_update'] = 1;//修改按钮
                } else {
                    $vo['is_delete'] = 0;
                }
            }
        }
        $data['total'] = $total;
        $data['rows'] = $res;
        return json_encode($data);
    }

    /**
     * 审核通过
     */
    public function updateLife()
    {
        $cid = $_POST['cid'];
        if ($cid != '') {
            $where['life_id'] = $cid;
            $data['life_status'] = 1;//审核通过
            $data['examine_user_id'] = session('loginSession')['user_id'];//审核人UUID
            $res = Db::table('up_life')->where($where)->update($data);
            if ($res) {
                $returnData['status'] = 1;
                $returnData['msg'] = "审核成功";
                return json_encode($returnData);
            } else {
                $returnData['status'] = 0;
                $returnData['msg'] = "审核失败";
                return json_encode($returnData);
            }
        }
    }

    /**
     *审核不通过
     */
    public function refuseLife()
    {
        $cid = $_POST['cid'];
        if ($cid != '') {
            $where['life_id'] = $cid;
            $data['life_status'] = 2;//审核通过
            $data['examine_user_id'] = session('loginSession')['user_id'];//审核人UUID
            $res = Db::table('up_life')->where($where)->update($data);
            if ($res) {

                $team_id = session('loginSession')['team_id'];//团队ID
                $where1['team_id'] = $team_id;
                $where1['team_member_remove'] = 2;
                $team_member_user_id = Db::table('up_team_members')->where($where1)->column('team_member_user_id');
                $team_name = session('loginSession')['team_name'];//团队名称
                $msg1 = "{\"msg\":\"22\"}";
                $msg = $team_name.'团队发布了一条公众信息，快去查看！';
                $msg_data = array('msg'=>$msg,'code'=>22,'fid'=>$cid);
                $code=22;
                $this->sendJpush(1,$msg,$msg_data,$msg1,$team_member_user_id,$code);

                $returnData['status'] = 1;
                $returnData['msg'] = "审核成功";
                return json_encode($returnData);
            } else {
                $returnData['status'] = 0;
                $returnData['msg'] = "审核失败";
                return json_encode($returnData);
            }
        }
    }

    /**
     * 删除此公共
     */
    public function deleteLife()
    {

        $cid = $_POST['cid'];
        if ($cid != '') {
            $where['life_id'] = $cid;
            $res = Db::table('up_life')->where($where)->delete();
            if ($res) {
                $returnData['status'] = 1;
                $returnData['msg'] = "删除成功";
                return json_encode($returnData);
            } else {
                $returnData['status'] = 0;
                $returnData['msg'] = "删除失败";
                return json_encode($returnData);
            }
        }
    }

    /**
     * 公众信息详情
     */
    public function courseInfo()
    {
        $cid = $_POST['cid'];
        if ($cid != '') {
            $where['life_id'] = $cid;
            $res = Db::table('up_life')->where($where)->field('life_name,life_content,img_url')->find();
            $img_url = explode(',', $res['img_url']);
            $this->assign('res', $res);
            $this->assign('img_url', $img_url);
        }
        return $this->fetch('life/detail');
    }

    /**
     * 查询省
     */
    public function province()
    {
        $province = Db::table('up_area')->where('level', 1)->select();
        $data['province'] = $province;
        return json_encode($province);
    }

    /**
     * 查询市
     */
    public function city()
    {
        $city = $_POST['city'];
        $cityArray = Db::table('up_area')->where('pid', $city)->select();
        $data['cityArray'] = $cityArray;
        return json_encode($data);
    }

    /**
     * 查询区
     */
    public function area()
    {
        $area = $_POST['area'];
        $cityArray = Db::table('up_area')->where('pid', $area)->select();
        $data['cityArray'] = $cityArray;
        return json_encode($data);
    }

    /**
     * 添加列表页面
     */
    public function addLife()
    {
        $province = Db::table('up_area')->where('level', 1)->select();
        $where['region_fid'] = 'ZDvaTNytyem97oNtRh692WpwYW8C3YPr';
        $res = Db::table('up_dic_region')->where($where)->select();//查询字典表里面的属于生活管理的子分类
        $this->assign('province', $province);
        $this->assign("res", $res);
        $sh = '3';//发布权限
        $uid = session('loginSession')['user_id'];
        $whereMap['user_id'] = $uid;
        $user_id = Db::table('up_team')->where($whereMap)->field('user_id')->find();//查询这个团队的创建人

        if ($user_id == '') {//查询这个人在团队里面是否有发布权限
            $whereUp['team_id'] = session('loginSession')['team_id'];//团队ID
            $whereUp['team_member_user_id'] = $uid;
            //查询这个人在这个团队权限
            $team_member_role = Db::table('up_team_members')->where($whereUp)->field('team_member_role')->find();

            $whereRole['team_role'] = $team_member_role['team_member_role'];
            $whereRole['team_id'] = session('loginSession')['team_id'];//团队ID

            //查询这个在在这个群里面的权限
            $RoleArray = Db::table('up_team_role')->where($whereRole)->field('team_role_detail')->find();
            if (strpos($RoleArray['team_role_detail'], $sh) === false) {
                return 1;
            } else {
                return $this->fetch('life/addLife');

            }
        } else {
            return $this->fetch('life/addLife');
        }


    }
    public function insertLifePic()
    {
        $who = $_POST['who'];
        $name = $_FILES["thumb{$who}"]['name'];
        $name = explode('.',$name);
        $date = date('YmdHis');
        $rand = rand(100000,999999);
        $aa = $date . $rand . '.' . $name[1];
        $dir = $_SERVER['DOCUMENT_ROOT'];
        $url =  "http://".$_SERVER['HTTP_HOST'];
        if($name[1] != 'jpg' && $name[1] != 'png' && $name[1] != 'gif'){
            return json_encode(['status'=>0,'msg'=>'上传的图片格式不支持']);
        }
        if(!empty($_FILES["thumb{$who}"]['tmp_name'])){
            if(move_uploaded_file($_FILES["thumb{$who}"]['tmp_name'],"{$dir}/upload/{$aa}")){
                $msg = "{$url}/upload/{$aa}";
                $this->image_png_size_add("{$dir}/upload/{$aa}","{$dir}/upload/{$aa}");
                return json_encode(['status'=>200,'msg'=>$msg,'idid'=>$date.$rand]);
            }else{
                return json_encode(['status'=>0,'msg'=>'图片保存失败']);
            }
        }else{
            return json_encode(['status'=>0,'msg'=>'获取不到图片信息']);
        }
    }
    /*
     * 添加信息
     */
    public function insertLife()
    {
        $file_array =array();
        $uid = session('loginSession')['user_id'];
        $url_img = '';
        $str = 'eQVbebKPT0xHh6Cvgq3dTQQ6acEQt90Y';
        $teamCount = Db::table('up_app_config')->where('up_base_id', $str)->field('up_info_count')->find();//团队发布的条数
        $BeginDate = date('Y-m-01 00:00:00', strtotime(date("Y-m-d")));//当前月的第一天
        $EndDate = date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));//这个月的最后一天

        $team_id = session('loginSession')['team_id'];
        $user_id = Db::table('up_team')->where('user_id', $uid)->value('user_id');//查询这个团队的创建人
        $teamWhere['team_id'] = $team_id;
        $teamWhere['life_status'] = $team_id;
        $teamWhere['life_time'] = array('between', array($BeginDate, $EndDate));
        $count = Db::table('up_life')->where($teamWhere)->count();
        if ($count > $teamCount) {
            $returnData['status'] = 0;
            $returnData['msg'] = "当月发布条数已经发布完了,请下个月在发布";
            return json_encode($returnData);
        }
        $validata = new LifeValidate();

        if (!$validata->check($_POST)) {
            $returnData['status'] = 0;
            $returnData['msg'] = $validata->getError();
            return json_encode($returnData);
        } else {
            if (mb_strlen($_POST['life_name'], "utf-8") > 30) {
                $returnData['status'] = 0;
                $returnData['msg'] = "信息名称不能超过30个";
                return json_encode($returnData);
            }
            if ($_POST['template'] == 2) {//上传3张图片信息
                if ($_FILES['file']['name'][0] == '' || $_FILES['file']['name'][1] == '' || $_FILES['file']['name'][2] == '') {
                    $returnData['status'] = 0;
                    $returnData['msg'] = "信息模板和上传图片张数不相符合";
                    return json_encode($returnData);
                } else {
                    //3张图的第一张图

                    $rand = date('YmdHis') . rand(100000, 999999);
                    $exe = explode('.', $_FILES['file']['name'][0]);
                    $filePath = $_FILES['file']['tmp_name'][0];
                    $info = $this->qnCommon(2, $rand, $exe[1], $filePath);
                    if ($info['status'] == 200) {
                        $file_array[0] = QiNiu . $info['key'];
                    }
                    //3张图的第二张图

                    $rand1 = date('YmdHis') . rand(100000, 999999);
                    $exe1 = explode('.', $_FILES['file']['name'][1]);
                    $filePath1 = $_FILES['file']['tmp_name'][1];
                    $info1 = $this->qnCommon(2, $rand1, $exe1[1], $filePath1);
                    if ($info1['status'] == 200) {
                        $file_array[1] = QiNiu  . $info1['key'];
                    }
                    //3张图的第三张图
                    $rand2 = date('YmdHis') . rand(100000, 999999);
                    $exe2 = explode('.', $_FILES['file']['name'][2]);
                    $filePath2 = $_FILES['file']['tmp_name'][2];
                    $info2 = $this->qnCommon(2, $rand2, $exe2[1], $filePath2);
                    if ($info2['status'] == 200) {
                        $file_array[2] = QiNiu . $info2['key'];
                    }
                    if($info['status']!=200||$info1['status']!=200||$info2['status']!=200){
                        $returnData['status'] = 0;
                        $returnData['msg'] = "上传图片格式不对";
                        return json_encode($returnData);
                    }
                    $url_img = implode(',',$file_array);//切割成字符串
                }
            }else{//上传一张图的信息
                $rand = date('YmdHis') . rand(100000, 999999);
                $exe = explode('.', $_FILES['file']['name'][0]);
                $filePath = $_FILES['file']['tmp_name'][0];
                $info = $this->qnCommon(2, $rand, $exe[1], $filePath);
                if ($info['status'] == 200) {
                    $url_img = QiNiu . $info['key'];
                }
            }
            if(isset($_POST['insert_image'])){
                $img_array = $_POST['insert_image'];
                if($img_array){
                    $data['content_url']=implode(',',$img_array);
                }
            }

            $data['img_url'] = $url_img;
            $data['category_region_id'] = $_POST['region_name'];
            $data['life_name'] = $_POST['life_name'];
            $data['life_template'] = $_POST['template'];
            $data['life_time'] = date('Y-m-d H:i:s');
            $data['province'] = $_POST['province'];
            $data['city'] = $_POST['city'];
            $data['area'] = $_POST['area'];
            $data['team_id'] = $team_id;
            $data['publisher_uid_id'] = $uid;
            $data['life_content'] = $_POST['life_content'];
            $data['life_id'] = $this->getRandChar(32);
            $province = Db::table('up_area')->where('district_id', $_POST['province'])->value('district');//查询省
            $city = Db::table('up_area')->where('district_id', $_POST['city'])->value('district');//查询市
            $area = Db::table('up_area')->where('district_id', $_POST['area'])->value('district');//查询区
            $data['pca'] = $province . '-' . $city . '-' . $area;
            if ($user_id != '') {//团队创建人
                $data['examine_user_id'] = $uid;//如果是团队创建人不需要审核，审核人就是自己
                $data['life_status'] = 1;
            } else {
                $whereUp['team_id'] = session('loginSession')['team_id'];//团队ID
                $whereUp['team_member_user_id'] = $uid;
                //查询这个人在这个团队角色
                $team_member_role = Db::table('up_team_members')->where($whereUp)->field('team_member_role')->find();
                if ($team_member_role['team_member_role'] != '') {
                    $sh = '2';//审核的权限
                    $whereRole['team_role'] = $team_member_role['team_member_role'];
                    $whereRole['team_id'] = session('loginSession')['team_id'];//团队ID
                    //查询这个在在这个群里面的权限
                    $RoleArray = Db::table('up_team_role')->where($whereRole)->field('team_role_detail')->find();
                    if (strpos($RoleArray['team_role_detail'], $sh) !== false) {//证明这个管理员有审核的权限
                        $data['life_status'] = 1;
                        $data['examine_user_id'] = $uid;//如果是团队创建人不需要审核，审核人就是自己
                    }
                }
            }
            $res = Db::table('up_life')->insert($data);
            if ($res) {
                if($data['life_status']==1){
                    $team_id = session('loginSession')['team_id'];//团队ID
                    $where1['team_id'] = $team_id;
                    $where1['team_member_remove'] = 2;
                    $team_member_user_id = Db::table('up_team_members')->where($where1)->column('team_member_user_id');
                    $team_name = session('loginSession')['team_name'];//团队名称
                    $msg1 = "{\"msg\":\"22\"}";
                    $msg = $team_name.'团队发布了一条公众信息，快去查看！';
                    $msg_data = array('msg'=>$msg,'code'=>22,'fid'=>$data['life_id']);
                    $code=22;
                    $this->sendJpush(1,$msg,$msg_data,$msg1,$team_member_user_id,$code);
                }else{//审核权限
                    $team_id = session('loginSession')['team_id'];//团队ID
                    $where2['team_id'] = $team_id;
                    $where2['team_role_detail'] = array('like',"%1%");
                    $team_role = Db::table('up_team_role')->where($where2)->field('team_role')->select();
                    $where1['team_id'] = $team_id;
                    $where1['team_member_role'] = array('IN',$team_role);
                    $where1['team_member_remove'] = 2;
                    $team_member_user_id = Db::table('up_team_members')->where($where1)->column('team_member_user_id');
                    if(count($team_member_user_id)>0){
                        $team_name = session('loginSession')['team_name'];//团队名称
                        $msg1 = "{\"msg\":\"22\"}";
                        $msg = $team_name.'团队发布了一条公众信息，快去审核查看！';
                        $msg_data = array('msg'=>$msg,'code'=>22,'fid'=>$data['life_id']);
                        $code = 22;
                        $this->sendJpush(1,$msg,$msg_data,$msg1,$team_member_user_id,$code);
                    }
                }

                return json_encode(array("status" => 200, "msg" => "发布成功！"));
            } else {
                return json_encode(array("status" => 0, "msg" => "发布失败！"));
            }
        }

    }
    /***
     * 修改页面
     */
    public function updateLifeInfo(){
        $uid = session('loginSession')['user_id'];

        $nid = $_POST['nid'];
        $res = Db::table('up_life')->where('life_id',$nid)->find();
        $res['img_url']=explode(',',$res['img_url']);
        $province = Db::table('up_area')->where('level',1)->select();
        $city =Db::table('up_area')->where('pid',$res['province'])->field('district_id,district')->select();
        $area =Db::table('up_area')->where('pid',$res['city'])->field('district_id,district')->select();
        $where['region_fid'] = 'ZDvaTNytyem97oNtRh692WpwYW8C3YPr';
        $config = Db::table('up_dic_region')->where($where)->select();
        //编辑对应的处理——6张详情图
        $for_loop = array(4,5,6,7,8,9);
        $sixid = array();
        $sixsrc = array();
        $sixhave = array();
        $next = 4;
        $isten = 4;
        if($res['content_url']){
            $six = explode(',',$res['content_url']);
            $i = 4;
            foreach ($six as $v){
                $sixsrc[$i] = $v;
                $vv = explode('/',$v);
                $count = count($vv);
                $vvv = $vv[$count-1];
                $vvvv = explode('.',$vvv);
                $sixid[$i] = $vvvv[0];
                $sixhave[] = $i;
                $i++;
                $next = $i;
                $isten = $i;
            }
        }
        if($next > 9){$next = 4;}
        $this->assign('for_loop',$for_loop);
        $this->assign('sixid',$sixid);
        $this->assign('sixsrc',$sixsrc);
        $this->assign('sixhave',$sixhave);
        $this->assign('next',$next);
        $this->assign('isten',$isten);
        //编辑对应的处理——6张详情图
        $this->assign('res',$res);
        $this->assign('province',$province);
        $this->assign('city',$city);
        $this->assign('area',$area);
        $this->assign('config_list',$config);
        if($res['life_status']==1){
            return 2;
        }
        if($uid!=$res['publisher_uid_id']){
            return 1;
        }else{
            return $this->fetch('life/updateLifeInfo');

        }
    }

    /**
     * 编辑功能
     */
    public function updateLifeList(){
        $uid = session('loginSession')['user_id'];
        $file_name = $_FILES['file']['name']; //文件名字
        $where['life_id'] = $_POST['life_id'];
        $img_url = Db::table('up_life')->where($where)->field('img_url,life_template')->find();//查询图片信息
        $img_url_list = explode(',',$img_url['img_url']);
        $validata = new LifeValidate();
        if(!$validata->check($_POST)){
            $returnData['status'] = 0;
            $returnData['msg'] = $validata->getError();
            return json_encode($returnData);
        }else{
            if(mb_strlen($_POST['life_name'],"utf-8")>30){
                $returnData['status'] = 0;
                $returnData['msg'] = "信息名称不能超过30个";
                return json_encode($returnData);
            }
         //判断模板是1或者3的情况下
         if($_POST['template']==1||$_POST['template']==3){
            if(!empty($file_name[0])){//证明是上传新的图片了
                $rand = date('YmdHis').rand(100000,999999);
                $exe = explode('.',$_FILES['file']['name']);
                $filePath = $_FILES['file']['tmp_name'];
                $info = $this->qnCommon(2,$rand,$exe[1],$filePath);
                if($info['status']==200){
                    $data['img_url'] = QiNiu.$info['key'];
                }
            }else{
              if($img_url['life_template']==2){//如果是原来的模板是上传3张图片,删除数组的第2个和第3个元素值
                    unset($img_url_list[1]);
                    unset($img_url_list[2]);
              }
            }
          }else{
              //循环3次
             if($img_url['life_template']==2){//原来的模板是2上传3张图片的时候
                 for ($i=0;$i<3;$i++){
                     if(!empty($file_name[$i])){
                         $rands = date('YmdHis').rand(100000,999999);
                         $exes = explode('.',$file_name[$i]);
                         $filePaths = $file_name[$i];
                         $info = $this->qnCommon(2,$rands,$exes[1],$filePaths);
                         if($info['status']==200){
                             $img_url_list[$i] = QiNiu.$info['key'];
                         }
                     }
                 }
             }else{//原来的模板是1或者3的情况
                 if($_FILES['file']['tmp_name'][0]!=''){
                     $rand = date('YmdHis') . rand(100000, 999999);
                     $exe = explode('.', $_FILES['file']['name'][0]);
                     $filePath = $_FILES['file']['tmp_name'][0];
                     $info = $this->qnCommon(2, $rand, $exe[1], $filePath);
                     if ($info['status'] == 200) {
                         $img_url_list[0] = QiNiu . $info['key'];
                     }else{
                         $returnData['status'] = 0;
                         $returnData['msg'] = "上传图片格式不对";
                         return json_encode($returnData);
                     }
                 }

                 $rand1 = date('YmdHis') . rand(100000, 999999);
                 $exe1 = explode('.', $_FILES['file']['name'][1]);
                 $filePath1 = $_FILES['file']['tmp_name'][1];
                 $info1 = $this->qnCommon(2, $rand1, $exe1[1], $filePath1);
                 if ($info1['status'] == 200) {
                     $img_url_list[1] = QiNiu . $info1['key'];
                 }else{
                     $returnData['status'] = 0;
                     $returnData['msg'] = "上传图片格式不对";
                     return json_encode($returnData);
                 }
                 $rand2 = date('YmdHis') . rand(100000, 999999);
                 $exe2 = explode('.', $_FILES['file']['name'][2]);
                 $filePath2 = $_FILES['file']['tmp_name'][2];
                 $info2 = $this->qnCommon(2, $rand2, $exe2[1], $filePath2);
                 if ($info2['status'] == 200) {
                     $img_url_list[2] = QiNiu . $info2['key'];
                 }else{
                     $returnData['status'] = 0;
                     $returnData['msg'] = "上传图片格式不对";
                     return json_encode($returnData);
                 }
             }
         }
        if(isset($_POST['insert_image'])){
            $img_array = $_POST['insert_image'];
            if($img_array){
                $data['content_url']=implode(',',$img_array);
            }
        }
            $user_id = Db::table('up_team')->where('user_id', $uid)->value('user_id');//查询这个团队的创建人
            if ($user_id != '') {//团队创建人
                $data['life_status'] = 1;
            } else {
                $whereUp['team_id'] = session('loginSession')['team_id'];//团队ID
                $whereUp['team_member_user_id'] = $uid;
                //查询这个人在这个团队角色
                $team_member_role = Db::table('up_team_members')->where($whereUp)->field('team_member_role')->find();
                if ($team_member_role['team_member_role'] != '') {
                    $sh = '2';//审核的权限
                    $whereRole['team_role'] = $team_member_role['team_member_role'];
                    $whereRole['team_id'] = session('loginSession')['team_id'];//团队ID
                    //查询这个在在这个群里面的权限
                    $RoleArray = Db::table('up_team_role')->where($whereRole)->field('team_role_detail')->find();
                    if (strpos($RoleArray['team_role_detail'], $sh) !== false) {//证明这个管理员有审核的权限
                        $data['life_status'] = 1;
                    }else{
                        $data['life_status'] = 3;
                    }
                }
            }

        $url_img = implode(',',$img_url_list);//切割成字符串
        $data['category_region_id'] = $_POST['region_name'];
        $data['life_name'] = $_POST['life_name'];
        $data['life_template'] = $_POST['template'];
        $data['life_time'] = date('Y-m-d H:i:s');
        $data['img_url'] = $url_img;
        $data['province'] = $_POST['province'];
        $data['city'] = $_POST['city'];
        $data['area'] = $_POST['area'];
        $data['life_content'] = $_POST['life_content']?$_POST['life_content']:'';
        $data['examine_user_id'] = $uid;//证明审核人就是自己
        $province = Db::table('up_area')->where('district_id',$_POST['province'])->value('district');//查询省
        $city = Db::table('up_area')->where('district_id',$_POST['city'])->value('district');//查询市
        $area = Db::table('up_area')->where('district_id',$_POST['area'])->value('district');//查询区
        $data['pca'] = $province.'-'.$city.'-'.$area;

        $res = Db::table('up_life')->where($where)->update($data);
        if($res){
            return json_encode(array("status" => 1, "msg" => "修改成功！"));
        }else{
            return json_encode(array("status" => 0, "msg" => "修改失败！"));
        }
    }
    }

}